package th.co.exat.uap.model;

import com.channgam.dbmlib.sql.MySQLJDBC;
import com.channgam.dbmlib.sql.iDataAdapter;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import th.co.exat.uap.config.Config;
import th.co.exat.uap.util.date.FormateDate;

public class UAPData {

    private static iDataAdapter i;
    private static int numRows;
    private static String sqlNumRows;
    private String id;
    private String lineId;
    private String uapExitStation;
    private String uapExitStationName;
    private String uapEnterStation;
    private String uapDate;
    private String toUapDate;
    private String uapTime;
    private String carTypeId;
    private String carTypeName;
    private String colorId;
    private String colorName;
    private String brandId;
    private String brandName;
    private String plateNo;
    private String provinceId;
    private String provinceName;
    private double pay;
    private double rate;
    private double icCard;
    private String emp1;
    private String emp1Name;
    private String emp2;
    private String emp3;
    private String chanel;
    private String status;
    private String statusName;
    private String flag;
    private String flagImg;
    private String type;
    private String typeName;
    private String approve1Date;
    private String approve1By;
    private String approve2Date;
    private String approve2By;
    private String ownerPrefix;
    private String ownerFname;
    private String ownerLname;
    private String ownerAddress;
    private String ownerDistric1;
    private String ownerDistric2;
    private String ownerProvince;
    private String uapCreate;
    private String uapCreateBy;
    private String documentNo;

    public static UAPData getById(String id) throws Exception {
        UAPData ud = new UAPData();
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();
        String sql = "SELECT * FROM uap_trx_uap "
                + "WHERE id = '" + id + "' ";

        i.query(sql);
        while (i.resultNext()) {
            ud.setId(i.result().getString("id"));
            ud.setLineId(Stations.getLineByStationId(
                    i.result().getString("uap_exit_station")).getLineId());
            ud.setUapExitStation(i.result().getString("uap_exit_station"));
            ud.setUapExitStationName(Stations.getStationById(
                    i.result().getString("uap_exit_station")).getStationName());
            ud.setUapEnterStation(i.result().getString("uap_enter_station"));
            ud.setUapDate(FormateDate.convertDateTimeToWebapp(
                    i.result().getString("uap_date")));
            ud.setCarTypeId(i.result().getString("cartype_id"));
            ud.setCarTypeName(Car.getCarTypeById(
                    i.result().getString("cartype_id")).getCarTypeName());
            ud.setColorId(i.result().getString("color_id"));
            ud.setColorName(Car.getColorById(
                    i.result().getString("color_id")).getColorName());
            ud.setBrandId(i.result().getString("brand_id"));
            ud.setBrandName(Car.getBrandById(
                    i.result().getString("brand_id")).getBrandName());
            ud.setPlateNo(i.result().getString("plate_no"));
            ud.setProvinceId(i.result().getString("province_id"));
            ud.setProvinceName(Car.getProvinceById(
                    i.result().getString("province_id")).getProvinceName());
            ud.setPay(i.result().getDouble("pay"));
            ud.setRate(i.result().getDouble("rate"));
            ud.setEmp1(i.result().getString("emp1"));
            ud.setType(i.result().getString("type"));
            ud.setTypeName(UAPData.getTypeName(i.result().getString("type")));
            ud.setStatus(i.result().getString("status"));
            ud.setFlag(i.result().getString("flag"));
            ud.setFlagImg(i.result().getString("flag"));
            ud.setStatusName(UAPData.getStatusName(i.result().getString("status")));
            ud.setApprove1Date(i.result().getString("approve1_date"));
            ud.setApprove1By(i.result().getString("approve1_by"));
            ud.setApprove2Date(i.result().getString("approve2_date"));
            ud.setApprove2By(i.result().getString("approve2_by"));

            // Set Owner
            if (i.result().getString("owner_prefix").equals("null")) {
                ud.setOwnerPrefix("");
            } else {
                ud.setOwnerPrefix(i.result().getString("owner_prefix"));
            }

            if (i.result().getString("owner_fname").equals("null")) {
                ud.setOwnerFname("");
            } else {
                ud.setOwnerFname(i.result().getString("owner_fname"));
            }

            if (i.result().getString("owner_lname").equals("null")) {
                ud.setOwnerLname("");
            } else {
                ud.setOwnerLname(i.result().getString("owner_lname"));
            }

            if (i.result().getString("owner_address").equals("null")) {
                ud.setOwnerAddress("");
            } else {
                ud.setOwnerAddress(i.result().getString("owner_address"));
            }

            if (i.result().getString("owner_distric1").equals("null")) {
                ud.setOwnerDistric1("");
            } else {
                ud.setOwnerDistric1(i.result().getString("owner_distric1"));
            }

            if (i.result().getString("owner_distric2").equals("null")) {
                ud.setOwnerDistric2("");
            } else {
                ud.setOwnerDistric2(i.result().getString("owner_distric2"));
            }

            if (i.result().getString("owner_province").equals("null")) {
                ud.setOwnerProvince("");
            } else {
                ud.setOwnerProvince(i.result().getString("owner_province"));
            }


            ud.setUapCreate(FormateDate.convertDateTimeToWebapp(i.result().getString("uap_create")));
            ud.setUapCreateBy(i.result().getString("uap_createby"));
        }



        i.close();
        return ud;
    }

    public static List<UAPData> getDataList(UAPData u,
            int showRecord, int page) throws Exception {
        List<UAPData> l = new ArrayList<UAPData>();

        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        int gotoPage = 0;
        if (page <= 0) {
            page = 1;
        }

        gotoPage = (page - 1) * showRecord;
        String sql = "SELECT * "
                + "FROM uap_trx_uap "
                + "WHERE 1 ";

        String sqlNum = "SELECT COUNT(*) AS c "
                + "FROM uap_trx_uap "
                + "WHERE 1 ";

        if (u.getUapDate() != null) {
            if (!u.getUapDate().equals("")) {


                String uapDate = FormateDate.convertDateToDatabase(u.getUapDate());
                String toUapDate = "";

                if (u.getToUapDate() != null) {
                    if (!u.getToUapDate().equals("")) {
                        toUapDate = FormateDate.convertDateToDatabase(u.getToUapDate());
                    } else {
                        toUapDate = uapDate;
                    }
                }

                sql += "AND uap_date BETWEEN  '" + uapDate + " 00:00:00' AND '"
                        + toUapDate + " 23:59:00' ";
                sqlNum += "AND uap_date BETWEEN  '" + uapDate + " 00:00:00' AND '"
                        + toUapDate + " 23:59:00' ";
            }
        }

        if (u.getPlateNo() != null) {
            sql += "AND plate_no LIKE '%" + u.getPlateNo() + "%' ";
            sqlNum += "AND plate_no LIKE '%" + u.getPlateNo() + "%' ";
        }

        if (u.getUapExitStation() != null) {
            sql += "AND uap_exit_station LIKE '%" + u.getUapExitStation() + "%' ";
            sqlNum += "AND uap_exit_station LIKE '%" + u.getUapExitStation() + "%' ";
        }

        UAPData.sqlNumRows = sqlNum;

        sql += " ORDER BY uap_date ";
        sql += "LIMIT " + gotoPage + " , " + showRecord;

        i.query(sql);

        while (i.resultNext()) {
            UAPData ud = new UAPData();
            ud.setId(i.result().getString("id"));
            ud.setUapExitStation(i.result().getString("uap_exit_station"));
            ud.setUapExitStationName(Stations.getStationById(
                    i.result().getString("uap_exit_station")).getStationName());
            ud.setUapEnterStation(i.result().getString("uap_enter_station"));
            ud.setUapDate(FormateDate.convertDateTimeToWebapp(
                    i.result().getString("uap_date")));
            ud.setCarTypeId(i.result().getString("cartype_id"));
            ud.setColorId(i.result().getString("color_id"));
            ud.setBrandId(i.result().getString("brand_id"));
            ud.setPlateNo(i.result().getString("plate_no"));
            ud.setProvinceId(i.result().getString("province_id"));
            ud.setProvinceName(Car.getProvinceById(
                    i.result().getString("province_id")).getProvinceName());
            ud.setPay(i.result().getDouble("pay"));
            ud.setRate(i.result().getDouble("rate"));
            ud.setIcCard(i.result().getDouble("ic_card"));
            ud.setStatus(i.result().getString("status"));
            ud.setFlag(i.result().getString("flag"));
            ud.setFlagImg(i.result().getString("flag"));
            ud.setStatusName(UAPData.getStatusName(i.result().getString("status")));
            l.add(ud);
        }

        i.close();
        return l;
    }

    public static List<UAPData> getDataList(UAPData u, String status,
            int showRecord, int page) throws Exception {
        List<UAPData> l = new ArrayList<UAPData>();

        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        int gotoPage = 0;
        if (page <= 0) {
            page = 1;
        }

        gotoPage = (page - 1) * showRecord;
        String sql = "SELECT * "
                + "FROM uap_trx_uap "
                + "WHERE 1 ";

        String sqlNum = "SELECT COUNT(*) AS c "
                + "FROM uap_trx_uap "
                + "WHERE 1 ";

        if (status != null) {
            if (status.equals("Y")) {
                sql += "AND status not in ('R') ";
                sqlNum += "AND status not in ('R') ";
            } else if (status.equals("N")) {
                sql += "AND status in ('R') ";
                sqlNum += "AND status in ('R') ";
            } else if (status.equals("D")) {
                sql += "AND status = 'D' ";
                sqlNum += "AND status = 'D' ";
            } else if (status.equals("K")) {
                sql += "AND status = 'K' ";
                sqlNum += "AND status = 'K' ";
            } else if (status.equals("P1")) {
                sql += "AND status = 'P1' ";
                sqlNum += "AND status = 'P1' ";
            }
        }

        if (u.getUapDate() != null) {
            if (!u.getUapDate().equals("")) {


                String uapDate = FormateDate.convertDateToDatabase(u.getUapDate());
                String toUapDate = "";

                if (u.getToUapDate() != null) {
                    if (!u.getToUapDate().equals("")) {
                        toUapDate = FormateDate.convertDateToDatabase(u.getToUapDate());
                    } else {
                        toUapDate = uapDate;
                    }
                }

                sql += "AND uap_date BETWEEN  '" + uapDate + " 00:00:00' AND '"
                        + toUapDate + " 23:59:00' ";
                sqlNum += "AND uap_date BETWEEN  '" + uapDate + " 00:00:00' AND '"
                        + toUapDate + " 23:59:00' ";
            }
        }

        if (u.getPlateNo() != null) {
            sql += "AND plate_no LIKE '%" + u.getPlateNo() + "%' ";
            sqlNum += "AND plate_no LIKE '%" + u.getPlateNo() + "%' ";
        }

        if (u.getUapExitStation() != null) {
            sql += "AND uap_exit_station LIKE '%" + u.getUapExitStation() + "%' ";
            sqlNum += "AND uap_exit_station LIKE '%" + u.getUapExitStation() + "%' ";
        }

        if (u.getType() != null) {
            if (!u.getType().equals("")) {
                sql += "AND type LIKE '" + u.getType() + "' ";
                sqlNum += "AND type = '" + u.getType() + "' ";
            }
        }

        UAPData.sqlNumRows = sqlNum;

        sql += " ORDER BY uap_date ";
        sql += "LIMIT " + gotoPage + " , " + showRecord;

        i.query(sql);

        while (i.resultNext()) {
            UAPData ud = new UAPData();
            ud.setId(i.result().getString("id"));
            ud.setUapExitStation(i.result().getString("uap_exit_station"));
            ud.setUapExitStationName(Stations.getStationById(
                    i.result().getString("uap_exit_station")).getStationName());
            ud.setUapEnterStation(i.result().getString("uap_enter_station"));
            ud.setUapDate(FormateDate.convertDateTimeToWebapp(
                    i.result().getString("uap_date")));
            ud.setCarTypeId(i.result().getString("cartype_id"));
            ud.setColorId(i.result().getString("color_id"));
            ud.setBrandId(i.result().getString("brand_id"));
            ud.setPlateNo(i.result().getString("plate_no"));
            ud.setProvinceId(i.result().getString("province_id"));
            ud.setProvinceName(Car.getProvinceById(
                    i.result().getString("province_id")).getProvinceName());
            ud.setPay(i.result().getDouble("pay"));
            ud.setRate(i.result().getDouble("rate"));
            ud.setType(i.result().getString("type"));
            ud.setTypeName(UAPData.getTypeName(i.result().getString("type")));
            ud.setStatus(i.result().getString("status"));
            ud.setFlag(i.result().getString("flag"));
            ud.setFlagImg(i.result().getString("flag"));
            ud.setStatusName(UAPData.getStatusName(i.result().getString("status")));
            ud.setDocumentNo(i.result().getString("document_no"));
            l.add(ud);
        }

        i.close();
        return l;
    }

    public static List<UAPData> getDataList(UAPData u, String status) throws Exception {
        List<UAPData> l = new ArrayList<UAPData>();

        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();


        String sql = "SELECT * "
                + "FROM uap_trx_uap "
                + "WHERE 1 ";

        String sqlNum = "SELECT COUNT(*) AS c "
                + "FROM uap_trx_uap "
                + "WHERE 1 ";

        if (status != null) {
            if (status.equals("Y")) {
                sql += "AND status not in ('R') ";
                sqlNum += "AND status not in ('R') ";
            } else if (status.equals("N")) {
                sql += "AND status in ('R') ";
                sqlNum += "AND status in ('R') ";
            } else if (status.equals("D")) {
                sql += "AND status = 'D' ";
                sqlNum += "AND status = 'D' ";
            } else if (status.equals("K")) {
                sql += "AND status = 'K' ";
                sqlNum += "AND status = 'K' ";
            } else if (status.equals("P1")) {
                sql += "AND status = 'P1' ";
                sqlNum += "AND status = 'P1' ";
            }
        }

        if (u.getUapDate() != null) {
            if (!u.getUapDate().equals("")) {


                String uapDate = FormateDate.convertDateToDatabase(u.getUapDate());
                String toUapDate = "";

                if (u.getToUapDate() != null) {
                    if (!u.getToUapDate().equals("")) {
                        toUapDate = FormateDate.convertDateToDatabase(u.getToUapDate());
                    } else {
                        toUapDate = uapDate;
                    }
                }

                sql += "AND uap_date BETWEEN  '" + uapDate + " 00:00:00' AND '"
                        + toUapDate + " 23:59:00' ";
                sqlNum += "AND uap_date BETWEEN  '" + uapDate + " 00:00:00' AND '"
                        + toUapDate + " 23:59:00' ";
            }
        }

        if (u.getPlateNo() != null) {
            sql += "AND plate_no LIKE '%" + u.getPlateNo() + "%' ";
            sqlNum += "AND plate_no LIKE '%" + u.getPlateNo() + "%' ";
        }

        if (u.getUapExitStation() != null) {
            sql += "AND uap_exit_station LIKE '%" + u.getUapExitStation() + "%' ";
            sqlNum += "AND uap_exit_station LIKE '%" + u.getUapExitStation() + "%' ";
        }

        if (u.getType() != null) {
            if (!u.getType().equals("")) {
                sql += "AND type LIKE '" + u.getType() + "' ";
                sqlNum += "AND type = '" + u.getType() + "' ";
            }
        }

        UAPData.sqlNumRows = sqlNum;

        sql += " ORDER BY uap_date ";

        i.query(sql);

        while (i.resultNext()) {
            UAPData ud = new UAPData();
            ud.setId(i.result().getString("id"));
            ud.setUapExitStation(i.result().getString("uap_exit_station"));
            ud.setUapExitStationName(Stations.getStationById(
                    i.result().getString("uap_exit_station")).getStationName());
            ud.setUapEnterStation(i.result().getString("uap_enter_station"));
            ud.setUapDate(FormateDate.convertDateTimeToWebapp(
                    i.result().getString("uap_date")));
            ud.setCarTypeId(i.result().getString("cartype_id"));
            ud.setColorId(i.result().getString("color_id"));
            ud.setBrandId(i.result().getString("brand_id"));
            ud.setPlateNo(i.result().getString("plate_no"));
            ud.setProvinceId(i.result().getString("province_id"));
            ud.setProvinceName(Car.getProvinceById(
                    i.result().getString("province_id")).getProvinceName());
            ud.setPay(i.result().getDouble("pay"));
            ud.setRate(i.result().getDouble("rate"));
            ud.setType(i.result().getString("type"));
            ud.setTypeName(UAPData.getTypeName(i.result().getString("type")));
            ud.setStatus(i.result().getString("status"));
            ud.setFlag(i.result().getString("flag"));
            ud.setFlagImg(i.result().getString("flag"));
            ud.setStatusName(UAPData.getStatusName(i.result().getString("status")));
            ud.setOwnerPrefix(i.result().getString("owner_prefix"));
            ud.setOwnerFname(i.result().getString("owner_fname"));
            ud.setOwnerLname(i.result().getString("owner_lname"));
            ud.setOwnerAddress(i.result().getString("owner_address"));
            ud.setOwnerDistric1(i.result().getString("owner_distric1"));
            ud.setOwnerDistric2(i.result().getString("owner_distric2"));
            ud.setOwnerProvince(i.result().getString("owner_province"));
            ud.setDocumentNo(i.result().getString("document_no"));
            l.add(ud);
        }

        i.close();
        return l;
    }

    public static int getNumRows() throws Exception {
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        i.query(UAPData.sqlNumRows);
        while (i.resultNext()) {
            numRows = i.result().getInt("c");
        }

        i.close();

        return numRows;
    }

    public static int insertUapData(UAPData u) throws Exception {
        int ex = 0;
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        String sql = "INSERT INTO uap_trx_uap "
                + "(uap_exit_station , uap_enter_station , uap_date,  "
                + "cartype_id, color_id, brand_id, plate_no, province_id, pay, rate, "
                + "ic_card, emp1, emp2, emp3, chanel, type, "
                + "owner_prefix, owner_fname, owner_lname, owner_address, "
                + "owner_distric1, owner_distric2, owner_province, uap_createby) "
                + "VALUES "
                + "('" + u.getUapExitStation() + "',"
                + "'" + u.getUapEnterStation() + "',"
                + "'" + u.getUapDate() + "',"
                + "'" + u.getCarTypeId() + "', "
                + "'" + u.getColorId() + "',"
                + "'" + u.getBrandId() + "',"
                + "'" + u.getPlateNo() + "',"
                + "'" + u.getProvinceId() + "',"
                + "'" + u.getPay() + "',"
                + "'" + u.getRate() + "',"
                + "'" + u.getIcCard() + "',"
                + "'" + u.getEmp1() + "',"
                + "'" + u.getEmp2() + "',"
                + "'" + u.getEmp3() + "',"
                + "'" + u.getChanel() + "',"
                + "'" + u.getType() + "',"
                + "'" + u.getOwnerPrefix() + "',"
                + "'" + u.getOwnerFname() + "',"
                + "'" + u.getOwnerLname() + "',"
                + "'" + u.getOwnerAddress() + "',"
                + "'" + u.getOwnerDistric1() + "',"
                + "'" + u.getOwnerDistric2() + "',"
                + "'" + u.getOwnerProvince() + "',"
                + "'" + u.getUapCreateBy() + "')";

        i.statement(sql);
        ex = i.execute();
        i.close();
        return ex;
    }

    public static int updateData(String id, UAPData u) throws Exception {
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        String sql = "UPDATE uap_trx_uap SET ";

        if (u.getUapExitStation() != null) {
            sql += "uap_exit_station  = '" + u.getUapExitStation() + "' ,";
        }

        if (u.getStatus() != null) {
            sql += "status = '" + u.getStatus() + "' ,";
        }
        if (u.getType() != null) {
            sql += "type = '" + u.getType() + "' ,";
        }
        if (u.getOwnerPrefix() != null) {
            sql += "owner_prefix = '" + u.getOwnerPrefix() + "' ,";
        }
        if (u.getOwnerFname() != null) {
            sql += "owner_fname = '" + u.getOwnerFname() + "' ,";
        }
        if (u.getOwnerLname() != null) {
            sql += "owner_lname = '" + u.getOwnerLname() + "' ,";
        }
        if (u.getOwnerAddress() != null) {
            sql += "owner_address = '" + u.getOwnerAddress() + "' ,";
        }
        if (u.getOwnerDistric1() != null) {
            sql += "owner_distric1 = '" + u.getOwnerDistric1() + "' ,";
        }
        if (u.getOwnerDistric2() != null) {
            sql += "owner_distric2 = '" + u.getOwnerDistric2() + "' ,";
        }

        sql += "flag = 'P' ";
        sql += "WHERE id = '" + id + "' ";


        i.statement(sql);
        return i.execute();
    }

    public static int updateStatus(String id, String status) throws Exception {
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        String sql = "UPDATE uap_trx_uap "
                + "SET status = '" + status + "' "
                + "WHERE id = '" + id + "' ";

        i.statement(sql);
        return i.execute();
    }

    public static int updateStatus(String id, String status,
            String approve1Date, String approve1By) throws Exception {
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        String sql = "UPDATE uap_trx_uap "
                + "SET status = '" + status + "' ,"
                + "approve1_date = '" + approve1Date + "' ,"
                + "approve1_by = '" + approve1By + "'"
                + "WHERE id = '" + id + "' ";

        i.statement(sql);
        return i.execute();
    }

    public static int updateReportApprove(String id,
            String status,
            String approveDate,
            String approveBy,
            String documentNo) throws Exception {
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        String sql = "UPDATE uap_trx_uap "
                + "SET status = '" + status + "', "
                + "approve2_date = '" + approveDate + "' , "
                + "approve2_by = '" + approveBy + "' , "
                + "document_no = '" + documentNo + "' "
                + "WHERE id = '" + id + "' ";

        i.statement(sql);
        return i.execute();
    }

    public static int getDocumentNo(String uapDate) throws ParseException, Exception {
        Locale locale = new Locale("th", "TH");
        DateFormat dateSource = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", locale);
        Date d = dateSource.parse(uapDate);
        DateFormat dateDestination = new SimpleDateFormat("yyMM", locale);

        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();
        String sql = "SELECT document_no FROM uap_trx_uap "
                + "WHERE document_no LIKE '%" + dateDestination.format(d) + "%' "
                + "ORDER BY document_no DESC ";

        i.query(sql);

        int curentDoc = 0;
        int nextDoc = 0;
        while (i.resultNext()) {
            curentDoc = i.result().getInt("document_no");
        }

        if (curentDoc == 0) {
            String strNextDoc = dateDestination.format(d) + "0001";
            nextDoc = Integer.parseInt(strNextDoc);
        } else {
            nextDoc = curentDoc + 1;
        }

        i.close();
        return nextDoc;
    }

    public String getDocumentNo() {
        return documentNo;
    }

    public void setDocumentNo(String documentNo) {
        this.documentNo = documentNo;
    }

    public static String getTypeName(String type) {
        String typeName = "";
        if (type.equals("T")) {
            typeName = "ตรงขนส่ง";
        } else if (type.equals("M")) {
            typeName = "ไม่ตรงขนส่ง";
        } else if (type.equals("N")) {
            typeName = "ไม่มีในขนส่ง";
        }
        return typeName;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getLineId() {
        return lineId;
    }

    public void setLineId(String lineId) {
        this.lineId = lineId;
    }

    public String getCarTypeName() {
        return carTypeName;
    }

    public void setCarTypeName(String carTypeName) {
        this.carTypeName = carTypeName;
    }

    public String getBrandName() {
        return brandName;
    }

    public void setBrandName(String brandName) {
        this.brandName = brandName;
    }

    public String getColorName() {
        return colorName;
    }

    public void setColorName(String colorName) {
        this.colorName = colorName;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getFlagImg() {
        return flagImg;
    }

    public void setFlagImg(String flagImg) {

        if (flagImg.equals("D")) {
            this.flagImg = "<img src=\"theme/images/icons/trash.png\" />";
        } else {
            this.flagImg = "";
        }
    }

    public String getApprove2By() {
        return approve2By;
    }

    public void setApprove2By(String approve2By) {
        this.approve2By = approve2By;
    }

    public String getApprove2Date() {
        return approve2Date;
    }

    public void setApprove2Date(String approve2Date) {
        this.approve2Date = approve2Date;
    }

    public String getApprove1By() {
        return approve1By;
    }

    public void setApprove1By(String apprive1By) {
        this.approve1By = apprive1By;
    }

    public String getApprove1Date() {
        return approve1Date;
    }

    public void setApprove1Date(String approve1Date) {
        this.approve1Date = approve1Date;
    }

    public String getOwnerAddress() {
        return ownerAddress;
    }

    public void setOwnerAddress(String ownerAddress) {
        this.ownerAddress = ownerAddress;
    }

    public String getOwnerDistric1() {
        return ownerDistric1;
    }

    public void setOwnerDistric1(String ownerDistric1) {
        this.ownerDistric1 = ownerDistric1;
    }

    public String getOwnerDistric2() {
        return ownerDistric2;
    }

    public void setOwnerDistric2(String ownerDistric2) {
        this.ownerDistric2 = ownerDistric2;
    }

    public String getOwnerFname() {
        return ownerFname;
    }

    public void setOwnerFname(String ownerFname) {
        this.ownerFname = ownerFname;
    }

    public String getOwnerLname() {
        return ownerLname;
    }

    public void setOwnerLname(String ownerLname) {
        this.ownerLname = ownerLname;
    }

    public String getOwnerPrefix() {
        return ownerPrefix;
    }

    public void setOwnerPrefix(String ownerPrefix) {
        this.ownerPrefix = ownerPrefix;
    }

    public String getOwnerProvince() {
        return ownerProvince;
    }

    public void setOwnerProvince(String ownerProvince) {
        this.ownerProvince = ownerProvince;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public String getToUapDate() {
        return toUapDate;
    }

    public void setToUapDate(String toUapDate) {
        this.toUapDate = toUapDate;
    }

    public static String getStatusName(String status) {
        String statusName = "";
        if (status.equals("R")) {
            statusName = "หพ.บันทึกรายการ";
        } else if (status.equals("D")) {
            statusName = "แผนกอนุมัติ";
        } else if (status.equals("K")) {
            statusName = "ยืนยันเรียกเก็บ";
        } else if (status.equals("P1")) {
            statusName = "ออกใบทวงหนี้";
        } else if (status.equals("PY")) {
            statusName = "ชำระเงิน";
        }

        return statusName;
    }

    public String getStatusName() {
        return statusName;
    }

    public void setStatusName(String statusName) {
        this.statusName = statusName;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public static String getProvinceName(String provinceId) throws Exception {
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        String sql = "SELECT province_name FROM uap_mst_province "
                + "WHERE id = '" + provinceId + "' ";

        i.query(sql);
        i.resultNext();

        return i.result().getString("province_name");
    }

    public static String getBrandName(String brandId) throws Exception {
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        String sql = "SELECT brand_name FROM uap_mst_brand "
                + "WHERE id = '" + brandId + "' ";

        i.query(sql);
        i.resultNext();

        return i.result().getString("brand_name");
    }

    public static String getColorName(String colorId) throws Exception {
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();

        String sql = "SELECT color_name FROM uap_mst_color "
                + "WHERE id = '" + colorId + "' ";

        i.query(sql);
        i.resultNext();

        return i.result().getString("color_name");
    }


    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public String getUapExitStationName() {
        return uapExitStationName;
    }

    public void setUapExitStationName(String uapExitStationName) {
        this.uapExitStationName = uapExitStationName;
    }

    public String getBrandId() {
        return brandId;
    }

    public void setBrandId(String brandId) {
        this.brandId = brandId;
    }

    public String getCarTypeId() {
        return carTypeId;
    }

    public void setCarTypeId(String carTypeId) {
        this.carTypeId = carTypeId;
    }

    public String getChanel() {
        return chanel;
    }

    public void setChanel(String chanel) {
        this.chanel = chanel;
    }

    public String getColorId() {
        return colorId;
    }

    public void setColorId(String colorId) {
        this.colorId = colorId;
    }

    public String getEmp1() {
        return emp1;
    }

    public void setEmp1(String emp1) {
        this.emp1 = emp1;
    }

    public String getEmp2() {
        return emp2;
    }

    public void setEmp2(String emp2) {
        this.emp2 = emp2;
    }

    public String getEmp3() {
        return emp3;
    }

    public void setEmp3(String emp3) {
        this.emp3 = emp3;
    }

    public double getIcCard() {
        return icCard;
    }

    public void setIcCard(double icCard) {
        this.icCard = icCard;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getPay() {
        return pay;
    }

    public void setPay(double pay) {
        this.pay = pay;
    }

    public String getPlateNo() {
        return plateNo;
    }

    public void setPlateNo(String plateNo) {
        this.plateNo = plateNo;
    }

    public String getProvinceId() {
        return provinceId;
    }

    public void setProvinceId(String provinceId) {
        this.provinceId = provinceId;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getUapCreate() {
        return uapCreate;
    }

    public void setUapCreate(String uapCreate) {
        this.uapCreate = uapCreate;
    }

    public String getUapCreateBy() {
        return uapCreateBy;
    }

    public void setUapCreateBy(String uapCreateBy) {
        this.uapCreateBy = uapCreateBy;
    }

    public String getUapDate() {
        return uapDate;
    }

    public void setUapDate(String uapDate) {
        this.uapDate = uapDate;
    }

    public String getUapEnterStation() {
        return uapEnterStation;
    }

    public void setUapEnterStation(String uapEnterStation) {
        this.uapEnterStation = uapEnterStation;
    }

    public String getUapExitStation() {
        return uapExitStation;
    }

    public void setUapExitStation(String uapExitStation) {
        this.uapExitStation = uapExitStation;
    }

    public String getUapTime() {
        return uapTime;
    }

    public void setUapTime(String uapTime) {
        this.uapTime = uapTime;
    }
}
